<?php
declare(strict_types=1);

namespace App\Common\Modular\Administer\Search;

use Core\Basics\BasicsSearch;
use Hyperf\Database\Model\Builder;
use Zms\Unit\Is;
use App\Common\Query\Query;
use App\Common\Modular\Administer\Serve\UserServe;

class UserSearch extends BasicsSearch
{
    public function query(): Builder
    {
        return container(UserServe::class)->query()
            ->when(isset($this->where['name']) && Is::notEmpty($this->where['name']), function (Builder $query) {
                Query::LikeSearch($query, 'name', $this->where['name']);
            })
            ->when(isset($this->where['value']) && Is::notEmpty($this->where['value']), function (Builder $query) {
                Query::EqualOrInSearch($query, 'id', $this->where['value']);
            })
            ->when(isset($this->where['status']) && Is::notEmpty($this->where['status']), function (Builder $query) {
                $query->where('status', $this->where['status']);
            })
            ->when(isset($this->where['id']) && Is::notEmpty($this->where['id']), function (Builder $query) {
                Query::EqualOrInSearch($query, 'id', $this->where['id']);
            })
            ->orderByRaw($this->order);
    }


    public function export(string $filename): array
    {
        return [];
    }

}